﻿/*** MikeWare Framework ************************************
* This class is part of product of MikeWare.Framework.
* 
* Author      : Mike Cheers
* Mail        : mikecheers@126.com
* Create Date : 2018/9/14
* Summary     : 
* 
* 
* Modified By : 
* Date        : 
* Mail        : 
* Comment     : 
**************************************************************/

namespace MikeWare.Core.Configurations
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;

    public class ConfigGroups : ICollection, IDisposable
    {
        private static object locker = new object();

        private ICollection<string> collection = null;

        public void CopyTo(Array array, int index)
        {
            //throw new NotImplementedException();
        }

        public int Count
        {
            get
            {
                if (null == collection) return 0;
                else return collection.Count;
            }
        }

        public bool IsSynchronized
        {
            get { return null == locker; }
        }

        public object SyncRoot
        {
            get { return locker; }
        }

        public IEnumerator GetEnumerator()
        {
            return collection.GetEnumerator();
        }

        public String this[int i]
        {
            get
            {
                if (null != collection)
                    return collection.Skip<string>(i).FirstOrDefault<string>();
                else
                    return null;
            }
        }

        public void Add(string item)
        {
            lock (locker)
            {
                if (null == collection)
                    collection = new List<string>();

                collection.Add(item);
            }
        }

        public void Dispose()
        {
            collection = null;
            locker = null;
        }
    }
}
